package com.cssl.controller;

import com.cssl.dto.AddProductDTO;
import com.cssl.entity.Product;
import com.cssl.service.ProductService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Map;

@RefreshScope
@RestController
@Tag(name = "商品控制器")
public class GoodsController {
    @Autowired
    private ProductService ps; //商品表

    @PostMapping("/ownProduct")
    public List<Product> ownProduct(){
        return ps.list();
    }

    /**
     * 添加商品 加商品图片
     * @param file
     * @param addDto
     * @return
     */
    @PostMapping("/addProduct")
    public Map<String,Object> addProduct(@RequestParam("file") MultipartFile file, AddProductDTO addDto){
        return ps.addProduct(file,addDto);
    }
}
